from pydantic import BaseModel, EmailStr
from typing import Optional
from datetime import datetime, date
# Pydantic 验证数据模型
class UserBase(BaseModel):
    phone: Optional[str] = None
    email: Optional[EmailStr] = None

class UserCreate(UserBase):
    phone: str
    email: EmailStr

class UserUpdate(UserBase):
    pass

class UserOut(BaseModel):
    id: int
    username: str
    phone: str
    email: EmailStr
    created_at: Optional[datetime] = None

    class Config:
        from_attributes = True

# 添加用户注册模式
class UserRegister(BaseModel):
    username: str
    phone: str
    email: EmailStr
    password: str

# 添加用户登录模式
class UserLogin(BaseModel):
    username: str  # 可以是用户名、手机号或邮箱
    password: str

# 添加登录响应模式
class UserLoginResponse(BaseModel):
    id: int
    username: str
    phone: str
    email: EmailStr
    message: str = "登录成功"
    
    class Config:
        from_attributes = True
